<?php

namespace App\Miya\Tools;

use GuzzleHttp\Client;

class NoteTool
{
    protected $token = '886d7cee96ce65214e326c73e9a5ed67';
    protected $apiUrl = 'http://v.juhe.cn/sms/send?';

    static public function sendMsg($tpl, $phone, $data)
    {
        $reg = "/^1\d{10}$/";
        $result = preg_match($reg, $phone);
        if (!$result) return;

        $params = [
            'tpl_id' => $tpl,
            'key' => (new static())->token,
            'mobile' => $phone,
            'tpl_value' => urlencode($data),
        ];

        $client = new Client();
        $client->request('POST', (new static())->apiUrl, ['form_params' => $params]);
    }
}
